package cn.itcast.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.transit.SignInfoRepository;
import cn.itcast.bos.dao.transit.TransitInfoRepository;
import cn.itcast.bos.domain.transit.SignInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.index.WayBillIndexRepository;
import cn.itcast.bos.service.transit.SignInfoService;
@Service
@Transactional
@SuppressWarnings("all")
public class SignInfoServiceimpl implements SignInfoService{
    @Autowired
    private SignInfoRepository signInfoRepository;
    @Autowired
    private TransitInfoRepository transitInfoRepository;
    @Autowired
    private WayBillIndexRepository wayBillIndexRepository;
    
	@Override
	public void save(SignInfo signInfo, String transitInfoId) {
	      signInfoRepository.save(signInfo);
	      TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(transitInfoId));
	      transitInfo.setSignInfo(signInfo);
	      if(signInfo.getSignType().equals("正常")){
	    	  transitInfo.setStatus("正常签收");
	    	  transitInfo.getWayBill().setSignStatus(3);
	    	  wayBillIndexRepository.save(transitInfo.getWayBill());
	      }else{
	    	  //异常
	    	  transitInfo.setStatus("异常签收");
	    	  transitInfo.getWayBill().setSignStatus(4);
	    	  //更改 索引库
	    	  wayBillIndexRepository.save(transitInfo.getWayBill());
	      }
	}

	
}
